package vlt.el.main;

import java.util.Map;

import vlt.el.db.DBConnection;
import vlt.el.db.SQLGenerator;
import vlt.el.db.dao.VltDAO;
import vlt.el.util.Config;

public class Main {

	public static void main(String[] args) throws Exception {
		System.out.println("hello");
		
		Config config = Config.getInstance();
		config.reloadConfigProperties();
		
		System.out.println( config.getConfigProperty("database.orig.url") );
		
		DBConnection db = new DBConnection();
		try{
			db.connectOrig(true);
			db.connectDest(true);
			SQLGenerator sqlGenerator = new SQLGenerator();
			String selectOrig = sqlGenerator.generateSelect(config.getConfigProperty("database.orig.owner"), config.getConfigProperty("database.orig.table"));
			System.out.println(selectOrig);
			Map<String, String> columns = sqlGenerator.listTableColumns(config.getConfigProperty("database.orig.owner"), config.getConfigProperty("database.orig.table"), db.getConnOrig());
			String insertDest = sqlGenerator.generateInsert(config.getConfigProperty("database.dest.owner"),config.getConfigProperty("database.dest.table"), columns);
			System.out.println(insertDest);
		    int rowsBeforeCommit = Integer.parseInt(config.getConfigProperty("database.rows_before_commit"));
		    
		    VltDAO dao = new VltDAO();
		    dao.load(db.getConnOrig(), db.getConnDest(), selectOrig, insertDest, columns, rowsBeforeCommit, 0);
			
		}catch (Exception e){
			e.printStackTrace();
		}finally{
			db.disconnectOrig();
			db.disconnectDest();
		}
	}
}
